﻿package com.saint{
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	public class SimpleGraphicBttn extends Sprite{
		
		private var defaultStroke:uint = 0x996600;
		private var defaultFill:uint = 0x99CC00;
		private var defaultWidth:uint;
		private var defaultHeight:uint;
		
		public function SimpleGraphicBttn(w:int = 10, h:int = 10) {
			defaultWidth = w;
			defaultHeight = h;
			drawBg();
			alpha = .1;
			setEnabled(true);
		}
		
		private function handleMouseUp(e:MouseEvent):void{
			dispatchEvent(new UpdateEvent("keyPress", this));
			handleMouseOut(null);
		}
		
		private function handleMouseOver(e:MouseEvent):void {
			alpha = 1;
		}
		
		private function handleMouseOut(e:MouseEvent):void{
			alpha = .1;
		}
		
		public function setEnabled(TF:Boolean):void{
			if(TF){
				buttonMode = true;
				mouseChildren = false;
				addEventListener(MouseEvent.ROLL_OVER, handleMouseOver, false, 0, true);
				addEventListener(MouseEvent.ROLL_OUT, handleMouseOut, false, 0, true);
				addEventListener(MouseEvent.MOUSE_UP, handleMouseUp, false, 0, true);
			}else{
				buttonMode = false;
				removeEventListener(MouseEvent.ROLL_OVER, handleMouseOver);
				removeEventListener(MouseEvent.ROLL_OUT, handleMouseOut);
				removeEventListener(MouseEvent.MOUSE_UP, handleMouseUp);
			}
		}
		
		private function drawBg():void {
			graphics.lineStyle(2, defaultStroke);
			graphics.beginFill(defaultFill, 1);
			graphics.drawRect(0, 0, defaultWidth, defaultHeight);
			graphics.endFill();
		}
	}
}